#include "vppacket.h"

void VpPacket::setSerial(int newSerial)
{
    m_serial = newSerial;
}

int VpPacket::serial() const
{
    return m_serial;
}

VpPacket::VpPacket()
{
    m_packet = av_packet_alloc();
    m_serial = 0;
}

VpPacket::~VpPacket()
{
    if(m_packet)
        av_packet_free(&m_packet);
}

VpPacket::VpPacket(const VpPacket &temp)
{
    m_packet = av_packet_alloc();
    if(temp.m_packet->pts != AV_NOPTS_VALUE) {
        av_packet_ref(m_packet, temp.m_packet);
        av_packet_copy_props(m_packet, temp.m_packet);
    }
    m_serial = temp.m_serial;
}

VpPacket &VpPacket::operator=(const VpPacket &temp)
{
    if(m_packet)
        av_packet_free(&m_packet);
    lock_guard<mutex> lock(m_mutex);
    m_packet = av_packet_alloc();
    if(temp.m_packet->pts != AV_NOPTS_VALUE) {
        av_packet_ref(m_packet, temp.m_packet);
        av_packet_copy_props(m_packet, temp.m_packet);
    }
    m_serial = temp.m_serial;
    return *this;
}
